package ex2;

import java.util.ArrayList;
import java.util.Scanner;
public class Test8 {
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList<String>();
		list.add("begin");
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String string = scanner.next();
			if (string.equals("!!end!!"))
				break;
			list.add(string);
		}
		list.add("end");
		System.out.println(list);
		scanner.nextLine();
		String string = scanner.nextLine();
		System.out.println(list.contains(string));
		System.out.println(list.indexOf(string));
		System.out.println(list.lastIndexOf(string));
		System.out.println(list.remove(0));
		System.out.println(list);
		list.set(1, scanner.nextLine());
		System.out.println(list);
		ArrayList<String> list1 = new ArrayList<String>();
		string = scanner.nextLine();
		for (String s : list)
			if (s.contains(string))
				list1.add(s);
		System.out.println(list1);
		for (int i = 1; i < list.size(); i++)
			if (list.get(i).equals(string)) {
				list.remove(i);
				break;
			}
		System.out.println(list);
		list.clear();
		System.out.println(list + " " + list.size() + "," + list.isEmpty());
		scanner.close();
	}
}